﻿package common
{
	
	import common.BitmapDataEx;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.geom.Matrix;
	import flash.geom.ColorTransform;
	import flash.geom.Rectangle;
	
	public class GraphicsEx 
	{
		private var _bmd:BitmapDataEx;
		private var _shape:Shape;
		
		public function GraphicsEx(bmd:BitmapDataEx)
		{
			_bmd = bmd;
			_shape = new Shape();
		}
		
		//-----------------------------------------------------------------------------------------------
		// call this method when you've finished drawing
		//-----------------------------------------------------------------------------------------------
		
		public function draw(matrix:Matrix = null, colorTransform:ColorTransform = null, blendMode:String = null, clipRect:Rectangle = null, smoothing:Boolean = false):void
		{
			_bmd.draw(_shape,matrix,colorTransform,blendMode,clipRect)
		}
		
		//-----------------------------------------------------------------------------------------------
		// The following methods are no more than wrappers around Shape.graphics calls  
		//-----------------------------------------------------------------------------------------------
		
		public function beginBitmapFill(bitmap:BitmapData, matrix:Matrix = null, repeat:Boolean = true, smooth:Boolean = false):void 
		{
			_shape.graphics.beginBitmapFill(bitmap, matrix, repeat, smooth);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function beginFill(color:uint, alpha:Number = 1.0):void  
		{
			_shape.graphics.beginFill(color,alpha);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function beginGradientFill(type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix = null, spreadMethod:String = "pad", interpolationMethod:String = "rgb", focalPointRatio:Number = 0):void 
		{
			_shape.graphics.beginGradientFill(type, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function clear():void
		{
			_shape.graphics.clear();
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function curveTo(controlX:Number, controlY:Number, anchorX:Number, anchorY:Number):void
		{
			_shape.graphics.curveTo(controlX, controlY, anchorX, anchorY);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function drawCircle(x:Number, y:Number, radius:Number):void 
		{
			_shape.graphics.drawCircle(x,y,radius);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function drawEllipse(x:Number, y:Number, width:Number, height:Number):void
		{
			_shape.graphics.drawEllipse(x, y, width, height);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function drawRect(x:Number, y:Number, width:Number, height:Number):void
		{
			_shape.graphics.drawRect(x, y, width, height);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function drawRoundRect(x:Number, y:Number, width:Number, height:Number, ellipseWidth:Number, ellipseHeight:Number):void
		{
			_shape.graphics.drawRoundRect(x, y, width, height, ellipseWidth, ellipseHeight);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function endFill():void
		{
			_shape.graphics.endFill();
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function lineGradientStyle(type:String, colors:Array, alphas:Array, ratios:Array, matrix:Matrix = null, spreadMethod:String = "pad", interpolationMethod:String = "rgb", focalPointRatio:Number = 0):void
		{
			_shape.graphics.lineGradientStyle(type, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function lineStyle(thickness:Number, color:uint = 0, alpha:Number = 1.0, pixelHinting:Boolean = false, scaleMode:String = "normal", caps:String = null, joints:String = null, miterLimit:Number = 3):void 
		{
			_shape.graphics.lineStyle(thickness,color,alpha,pixelHinting,scaleMode,caps,joints,miterLimit);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function lineTo(x:Number, y:Number):void 
		{
			_shape.graphics.lineTo(x, y);
		}
		
		//-----------------------------------------------------------------------------------------------
		
		public function moveTo(x:Number, y:Number):void
		{
			_shape.graphics.moveTo(x, y);
		}
		
		//-----------------------------------------------------------------------------------------------
		
	}
	
}